/* WrapperOverloading.java Created on 13/giu/2012 */
package it.tommasocortonesi.scjp.cap4;

/**
 * Studio dell'overloading per le classi wrapper
 *
 * @author 		tommasocortonesi
 * @version 	1.0, 13/giu/2012
 */
public class WrapperOverloading {

	/* Rules:
	 * 1.	Primitive Widening > Boxing > Varargs
	 * 2.	Widening and Boxing (WB) not allowed
	 * 3.	Boxing and Widening (BW) allowed
	 * 4.	While overloading, Widening (or the identity conversion) + vararg 
	 * 		and Boxing + vararg can only be used in a mutually exclusive 
	 * 		manner i.e. not together.
	 * 5.	(4') While overloading, vararg and unboxing + vararg can only 
	 * 		be used in a mutually exclusive manner i.e. not together.
	 * 6.	Widening between wrapper classes not allowed
	 */
	
	public static void main(String[] args) {
		WrapperOverloading wo = new WrapperOverloading();
		wo.doX(5);
		wo.doX(new Integer(5));

		//	Examples:
		//		
		//	doX(Integer i) & doX(long l)       doX(5)              long (by Rule 1)
		//	doX(int...i) & doX(Integer i)      doX(5)              Integer (by Rule 1)
		//	doX(Long l) & doX(int...i)         doX(5)              int...i (Rule 2 & 1)
		//	doX(Long l) & doX(Integer...i)     doX(5)              Integer...i(R. 2&1)
		//	doX(Object o) & doX(Long l)        doX(5)              Object o (Rule 2&3)
		//	doX(Object o) & doX(int...i)       doX(5)              Object o (Rule 3&1)
		//	doX(Object o) & doX(long l)        doX(5)              long l (Rule 3&1)
		//	doX(long...l) & doX(Integer...i)   doX(5)              ambiguous (Rule 4)
		//	doX(long...l) & doX(Integer i)     doX(5)              Integer (Rule 1)
		//	doX(Long l)                        doX(new Integer(5)) error (Rule 5)
		//	doX(Long l) & doX(long...l)        doX(new Integer(5)) long...l(Rule 5 & 1)
		//	doX(Integer... i) & doX(int...i)   doX(new Integer(1)) Ambiguous call (Rule 4 & 4')

	}
	
	void doX(Integer i) {System.out.println("doX(Integer i)");}
	void doX(long l) {System.out.println("doX(long l)");}
	void doX(int...i) {System.out.println("doX(int...i)");}
	void doX(Long l) {System.out.println("doX(Long l)");}
	void doX(Integer...i) {System.out.println("doX(Integer...i)");}
	void doX(Object o) {System.out.println("doX(Object o)");}
	void doX(long...l) {System.out.println("doX(long...l)");}
	
}
